﻿package mortal.game.view.group.cellRenderer
{
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.group.*;
    import mortal.mvc.core.*;

    public class NearPlayerCellRenderer extends GCellRenderer
    {
        private var _entityInfo:EntityInfo;
        private var _playerName:GTextFiled;
        private var _career:GTextFiled;
        private var _level:GTextFiled;
        private var _guildName:GTextFiled;
        private var _power:GTextFiled;
        private var _inviteBtn:GButton;

        public function NearPlayerCellRenderer()
        {
            this.mouseEnabled = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._career = UIFactory.gTextField("", 102, 0, 100, 20, this, _loc_1);
            this._level = UIFactory.gTextField("", 222, 0, 100, 20, this, _loc_1);
            this._guildName = UIFactory.gTextField("", 344, 0, 100, 20, this, _loc_1);
            _loc_1.underline = true;
            this._playerName = UIFactory.gTextField("", -22, 0, 160, 20, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatChen;
            _loc_1.align = AlignMode.CENTER;
            this._power = UIFactory.gTextField("", 479, 0, 100, 20, this, _loc_1);
            this._inviteBtn = UIFactory.gButton(Language.getString(30211), 652, -1, 67, 22, this);
            this._inviteBtn.configEventListener(MouseEvent.CLICK, this.inviteHandler);
            this.pushUIToDisposeVec(UIFactory.bg(0, 25, 760, 1, this, ImagesConst.SplitLine));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            PlayerMenuRegister.UnRegister(this._playerName);
            this._playerName.dispose(param1);
            this._career.dispose(param1);
            this._level.dispose(param1);
            this._guildName.dispose(param1);
            this._power.dispose(param1);
            this._inviteBtn.dispose(param1);
            this._playerName = null;
            this._career = null;
            this._level = null;
            this._guildName = null;
            this._power = null;
            this._inviteBtn = null;
            this._entityInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function inviteHandler(event:MouseEvent) : void
        {
            if (this._entityInfo.entityInfo.entityId.type != EEntityType._EEntityTypePlayer)
            {
                MsgManager.showRollTipsMsg(Language.getString(30253), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (this._entityInfo.entityInfo.level <= 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupGetNearPlayer));
                MsgManager.showRollTipsMsg(Language.getString(30253), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (!EntityUtil.isSameServer(this._entityInfo.entityInfo.entityId, Cache.instance.role.entityInfo.entityId))
            {
                MsgManager.showRollTipsMsg(Language.getString(35302), MsgRollTipsType.msgRollTips3);
                return;
            }
            var _loc_2:* = new Array();
            var _loc_3:* = new SGroupOper();
            _loc_3.fromEntityId = Cache.instance.role.entityInfo.entityId;
            _loc_3.toEntityId = this._entityInfo.entityInfo.entityId;
            _loc_3.fromPlayer = new SPublicPlayer();
            _loc_3.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
            _loc_3.type = EGroupOperType._EGroupOperTypeInvite;
            _loc_3.fromPlayer.guildId = new SEntityId();
            _loc_3.fromPlayer.copyId = new SEntityId();
            _loc_2.push(_loc_3);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteOper, _loc_2));
            return;
        }// end function

        private function setCareer(param1:int) : void
        {
            this._career.text = GameDefConfig.instance.getCarrer(param1);
            return;
        }// end function

        private function setCamp(param1:int) : void
        {
            this._guildName.text = this._entityInfo.entityInfo.guildName == "" ? (Language.getString(35301)) : (this._entityInfo.entityInfo.guildName);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:GroupCache = null;
            super.data = param1;
            this._entityInfo = param1.data;
            if (this._entityInfo.entityInfo.entityId.type != EEntityType._EEntityTypePlayer)
            {
                return;
            }
            this._inviteBtn.filters = [];
            if (this._entityInfo && this._entityInfo.entityInfo.level > 0)
            {
                this.setCareer(this._entityInfo.entityInfo.career);
                this.setCamp(this._entityInfo.entityInfo.camp);
                this._playerName.htmlText = "<a href=\'event:#\'>" + NameUtil.getProxyName(this._entityInfo.entityInfo.entityId) + this._entityInfo.entityInfo.name + "</a>";
                this._level.text = this._entityInfo.entityInfo.level.toString();
                this._power.text = this._entityInfo.entityInfo.combat.toString();
                _loc_2 = Cache.instance.group;
                if (_loc_2.players.length == 5 || !_loc_2.isCaptain && _loc_2.isInGroup && !_loc_2.memberInvite)
                {
                    this._inviteBtn.mouseEnabled = false;
                    this._inviteBtn.filters = [FilterConst.colorFilter2];
                }
                else
                {
                    this._inviteBtn.mouseEnabled = true;
                }
                if (!EntityUtil.isSameServer(this._entityInfo.entityInfo.entityId, Cache.instance.role.entityInfo.entityId))
                {
                    this._inviteBtn.filters = [FilterConst.colorFilter2];
                }
                PlayerMenuRegister.Register(this._playerName, this._entityInfo, PlayerMenuConst.NearbyPlayerOpMenu);
            }
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            return;
        }// end function

    }
}
